package com.cskaoyan.controller;

import com.cskaoyan.anno.LogRecord;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.model.MarketAd;
import com.cskaoyan.model.MarketBrand;
import com.cskaoyan.model.MarketGoods;
import com.cskaoyan.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @Author zoe ling
 * @Date 2024/6/8
 */
@RestController
@RequestMapping("wx/home")
public class WxHomeController {
    @Autowired
    Adservice adservice;
    @Autowired
    CategoryService categoryService;
    @Autowired
    SystemService systemService;
    @Autowired
    BrandService brandService;
    @Autowired
    GoodsService goodsService;
    @Autowired
    private TopicService topicService;
    @Autowired
    private CouponService couponService;
    @LogRecord
    @GetMapping("index")
    public BaseRespVo index(){
        Map<String, Object> dataMap=new HashMap<>();
        List<MarketAd> banners=adservice.query();
        List channels=categoryService.queryLevelOne();

        dataMap.put("banner",banners);
        dataMap.put("channel",channels);
        //获取system表中的数据
        Map<String,String> systemConfig = systemService.toMap();

        int brandLimit = Integer.parseInt(systemConfig.get("market_wx_index_brand"));
        List<MarketBrand> brandList = brandService.list(1, brandLimit);
        dataMap.put("brandList", brandList);

        //新品首发和人气推荐
        int hotLimit = Integer.parseInt(systemConfig.get("market_wx_index_hot"));
        int newLimit = Integer.parseInt(systemConfig.get("market_wx_index_new"));
        List<MarketGoods> hotGoodsList = goodsService.goodsList(true, false, 1, hotLimit);
        List<MarketGoods> newGoodsList = goodsService.goodsList(false, true, 1, newLimit);
        dataMap.put("hotGoodsList", hotGoodsList);
        dataMap.put("newGoodsList", newGoodsList);
        //专题精选
        //优惠券 没有登录就查询所有可用优惠券前三个
        List<Map> couponList=couponService.list(1,3);
        dataMap.put("couponList",couponList);
        //有登录就查询用户可用优惠券

        //floorGoodsList
        int categoryLimit = Integer.parseInt(systemConfig.get("market_wx_catlog_list"));
        int categoryGoodsLimit = Integer.parseInt(systemConfig.get("market_wx_catlog_goods"));
        List floorGoodsList=goodsService.floorGoodsList(categoryLimit,categoryGoodsLimit);
        dataMap.put("floorGoodsList",floorGoodsList);


        return BaseRespVo.ok(dataMap);
    }

}
